Search
Synchronizing custom taxonomies on Product Synchronization - WP Global Cart
17287
documentation-template-default,single,single-documentation,postid-17287,theme-awake,eltd-core-1.1,woocommerce-no-js,awake child-child-ver-1.0.0,awake-ver-1.0,eltd-smooth-scroll,eltd-smooth-page-transitions,eltd-mimic-ajax,eltd-grid-1200,eltd-blog-installed,eltd-default-style,eltd-fade-push-text-top,eltd-header-standard,eltd-sticky-header-on-scroll-down-up,eltd-default-mobile-header,eltd-sticky-up-mobile-header,eltd-menu-item-first-level-bg-color,eltd-dropdown-slide-from-top,eltd-,eltd-fullscreen-search eltd-search-fade,eltd-side-menu-slide-from-right,wpb-js-composer js-comp-ver-6.3.0,vc_responsive
 

Synchronizing custom taxonomies on Product Synchronization

WP Global Cart / Synchronizing custom taxonomies on Product Synchronization
Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInShare on TumblrPin on PinterestEmail this to someonePrint this page

Synchronizing custom taxonomies on Product Synchronization

By default, on Product Synchronization all product data will be migrated to the designated shops in the network. That includes the Product Category and Product Tag taxonomies.
When using custom taxonomies, to synchronize a custom one called ‘writer’ from the main product to its child products across different shops within a multi-site WooCommerce network, a custom code can be used.

The $taxnomy_name variable value should be updated accordingly to the actual local taxonomy name.

    add_filter( 'woogc/ps/synchronize_product/child_product', 'sync_custom_taxonomy_to_child_product', 10, 3 );
    function sync_custom_taxonomy_to_child_product( $child_product, $main_product_data, $origin_product_blog_ID ) 
        {
            $taxnomy_name   =   'writer';
            
            //switch back to the origin product shop
            switch_to_blog( $origin_product_blog_ID );
            
            $main_product   =   new WC_Product( $main_product_data[ 'id' ] );
            
            $main_product_terms_ids =   wp_get_object_terms( $main_product->get_ID(), $taxnomy_name, array( 'fields' => 'ids' ) ) ;
            
            restore_current_blog();
            
            if ( count (  $main_product_terms_ids ) > 0 )
                {
                    $WooGC_PS   =   new WooGC_PS();
                    
                    $WooGC_PS->synchronize_taxonomy ( $main_product_terms_ids, $child_product->get_ID(), $origin_product_blog_ID, $taxnomy_name );
                }
         
            return $child_product;
        }

The code should be placed inside theme functions.php or a custom file within /wp-content/mu-plugins/
Synchronizing custom taxonomies across multi-site WooCommerce networks ensures consistency and coherence in product management.

0
Would love your thoughts, please comment.x
()
x